#include "gameplay.h"

/* x e y sono le coordinate del mouse, gia' trasformate in coordinate della mappa */
void GamePlay::localProjectileShooted(Player *player, float x, float y)
{
	/* TODO: qui si dovra' gestire lo sparo del proiettile che conseguentemente invochera' il physics engine crendo l'entita' etc*/
	WorldPlayer* p = player->m_worldEntity;
	
	
	float dx = (p->x - x);
	float dy = (p->y - y);
	
	float unity = sqrt(dx*dx + dy*dy);
	
	dx /= unity;
	dy /= unity;
	
#ifdef DEBUG
	printf("dx: %f - dy: %f\r\n", dx, dy);
	fflush(stdout);
#endif
	
	//projectileShooted(1, player->x, player->y, Vector2D(80.0f*-dx,80.0f*-dy), Vector2D(0.0f,0.0f), Vector2D(0.0f,-3.0f),(WorldPlayer*)world->getEntity(3));
	
	projectileShooted(1, p->x, p->y, Vector2D(20.0f*-dx,20.0f*-dy), Vector2D(0.0f,0.0f), Vector2D(0.0f,-30.0f),(WorldPlayer*)world->getEntity(3));
}

void GamePlay::projectileShooted(int type, float x, float y, Vector2D vel, Vector2D acc, Vector2D gravity, WorldPlayer *owner)
{
	world->shootProjectile(type, x, y, vel, acc, gravity, owner);
}

void GamePlay::playerJumped(Player *player)
{
	player->m_worldEntity->isJumping = true;
	
	//printf("LOL: %f",player->m_worldEntity->velocity.y);
	//player->m_worldEntity->addForce(Vector2D(0.0f,80.0f));
}

void GamePlay::playerIsMoving(Player *player, char type)
{
	player->m_worldEntity->isMoving(type);
	
	/*if (type == MOVE_LEFT)
	{
		GLfloat x = world->getEntity(3)->velocity.getX();
		world->getEntity(3)->velocity.setX(x-10.0f);
	}
	else if (type == MOVE_RIGHT)
	{
		GLfloat x = world->getEntity(3)->velocity.getX();
		world->getEntity(3)->velocity.setX(x+10.0f);
	}*/
}

void GamePlay::playerStopped(Player *player, char type)
{
	player->m_worldEntity->stoppedMoving(type);
}


void GamePlay::collisionProjectileArea(WorldProjectile *projectile, WorldArea *area, float x, float y)
{
	world->removeEntity(projectile);
}
/*Parte danni ricevuti */
void GamePlay::dmgMeeleWeaponRecived(Player *target, Player *source, short hp)
{
	short res = target->m_myClass->getHitPoints() - hp;
	
	if(res >= 0)
	{
		/*TODO: metodo di informazione morte giocatore */
	}
	
	/*TODO: inserimento danni, fonte e tipo nel "combat log" */
}
 void GamePlay::dmgRangedWeaponRecived(Player *target, Player *source, short hp)
 {
	 short res = target->m_myClass->getHitPoints() - hp;
	 
	 if(res >= 0)
	 {
		 /*come sopra*/
	 }
	 
	 /*come sopra*/
 }
 
 void GamePlay::dmgAbilityRecevied(Player *target, Player *source, short hp)
 {
	 short res = target->m_myClass->getHitPoints() - hp;
	 
	 if(res >= 0)
	 {
		 /*come sopra*/
	 }
	 
	 /*come sopra*/
 }